package controller

import (
	"ollama-go/dto"
	"ollama-go/query"
	"ollama-go/service"

	"github.com/androidsr/sc-go/model"
	"github.com/androidsr/sc-go/sgin"
	"github.com/gin-gonic/gin"
)

func init() {
	sgin.AddRouter(CrawlerSelecterController{
		crawlerSelecterService: service.NewCrawlerSelecterService(),
	})
}

type CrawlerSelecterController struct {
	crawlerSelecterService *service.CrawlerSelecterService
}

// 查询
// @Router [get] [/crawlerselecter/:id]
func (m CrawlerSelecterController) Get(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.crawlerSelecterService.Get(id)
}

// 增加
// @Router [post] [/crawlerselecter]
func (m CrawlerSelecterController) Save(c *gin.Context, dto *dto.CrawlerSelecterDTO) any {
	dto.Id = ""
	return m.crawlerSelecterService.Save(dto)
}

// 修改
// @Router [put] [/crawlerselecter/edit]
func (m CrawlerSelecterController) UpdateById(c *gin.Context, dto *dto.CrawlerSelecterDTO) any {
	if dto.Id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	dto.TenantId = c.GetString(USER)
	return m.crawlerSelecterService.UpdateById(dto)

}

// 删除
// @Router [delete] [/crawlerselecter/:id]
func (m CrawlerSelecterController) DeleteById(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.crawlerSelecterService.DeleteById(id)
}

// 查询列表
// @Router [post] [/crawlerselecter/page]
func (m CrawlerSelecterController) QueryPage(c *gin.Context, query *query.CrawlerSelecterQueryDTO) any {
	return m.crawlerSelecterService.QueryPage(query)
}

// 分页下拉
// @Router [post] [/crawlerselecter/list]
func (m CrawlerSelecterController) QuerySelect(c *gin.Context, query *model.SelectQueryDTO) any {
	return m.crawlerSelecterService.QueryList(query)
}
